package com.usian.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.usian.admin.mapper.AdSensitiveMapper;
import com.usian.admin.service.AdSensitiveService;
import com.usian.model.admin.dtos.SensitiveDto;
import com.usian.model.admin.pojos.AdSensitive;
import com.usian.model.base.BaseServiceImpl;
import com.usian.model.common.dtos.ResponseResult;
import io.micrometer.core.instrument.util.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Date;


@Service
public class AdSensitiveServiceImpl extends BaseServiceImpl<AdSensitiveMapper, AdSensitive> implements AdSensitiveService {

    @Override
    public ResponseResult findAll(SensitiveDto sensitiveDto) {
        if (sensitiveDto == null) return errorParam;
        sensitiveDto.checkParam();
        LambdaQueryWrapper<SensitiveDto> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(StringUtils.isNotBlank(sensitiveDto.getName()),SensitiveDto::getName,sensitiveDto.getName());
        return getPage(sensitiveDto,wrapper);
    }

    @Override
    public ResponseResult add(AdSensitive adSensitive) {
        if (adSensitive == null)return errorParam;
        adSensitive.setCreatedTime(new Date());
        save(adSensitive);
        return successParam;
    }

    @Override
    public ResponseResult del(Integer id) {
        if (id == null) return errorParam;
        AdSensitive sensitive = getById(id);
        if (sensitive == null)return notExit;
        removeById(id);
        return successParam;
    }

    @Override
    public ResponseResult edit(AdSensitive adSensitive) {
        if (adSensitive == null)return errorParam;
        updateById(adSensitive);
        return successParam;
    }
}
